package com.heeexy.example.service.impl;

import com.alibaba.fastjson.JSONObject;
import com.heeexy.example.service.DBService;
import com.heeexy.example.dao.DBDao;
import com.heeexy.example.util.CommonUtil;
import com.heeexy.example.util.constants.ErrorEnum;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

@Service
public class DBserviceImpl implements DBService {
    @Autowired
    private DBDao dbDao;

    @Override
    @Transactional(rollbackFor = Exception.class)
    public JSONObject DBbackup(JSONObject jsonObject) {
        dbDao.DBbackup(jsonObject);
        return CommonUtil.successJson();
    }

    @Override
    public JSONObject listDB(JSONObject jsonObject) {
        CommonUtil.fillPageParam(jsonObject);
        int count = dbDao.countDB(jsonObject);
        List<JSONObject> list = dbDao.listDB(jsonObject);
        return CommonUtil.successPage(jsonObject, list, count);
    }

    @Override
    public JSONObject addDB(JSONObject jsonObject) {
        dbDao.addDB(jsonObject);
        return CommonUtil.successJson();
    }

    @Override
    public JSONObject deleteDB(JSONObject jsonObject) {
        dbDao.deleteDB(jsonObject);
        return CommonUtil.successJson();
    }

}
